#include<iostream>
using namespace std;
int main()
{
	int n,max=0,min=100,score;
	string maxname,maxid,minname,minid;
	string name,id;
	cin>>n;//scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		cin>>name>>id>>score;
		if(score>max){
			maxname=name;
			maxid=id;
			max=score;
		}
		if(score<min){
			minname=name;
			minid=id;
			min=score;
		}
	}
	cout<<maxname<<" "<<maxid<<endl<<minname<<" "<<minid;
	return 0;
} 
